package com.qzyh.esb.egsa.controller;

import cn.hutool.crypto.SecureUtil;
import com.qzyh.esb.egsa.utils.ResultObject;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.util.Base64;

@RestController
@Api(value = "测试Controller", tags = { "测试访问接口" })
public class DemoController {

    private static final Logger logger = LoggerFactory.getLogger(DemoController.class);


    //{"code":0,"type":"adminMenu","data":[{"path":"/home","name":"home","component":"home/index","meta":{"title":"首页","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":true,"isIframe":false,"roles":["admin","common"],"icon":"iconfont icon-shouye"}},{"path":"/system","name":"system","component":"layout/routerView/parent","redirect":"/system/menu","meta":{"title":"系统设置","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"iconfont icon-xitongshezhi"},"children":[{"path":"/system/menu","name":"systemMenu","component":"system/menu/index","meta":{"title":"菜单管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"iconfont icon-caidan"}},{"path":"/system/dept","name":"systemDept","component":"system/dept/index","meta":{"title":"部门管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"ele-OfficeBuilding"}},{"path":"/system/role","name":"systemRole","component":"system/role/index","meta":{"title":"角色管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"ele-ColdDrink"}},{"path":"/system/user","name":"systemUser","component":"system/user/index","meta":{"title":"用户管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"iconfont icon-icon-"}},{"path":"/system/dic","name":"systemDic","component":"system/dic/index","meta":{"title":"字典管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"ele-SetUp"}}]},{"path":"/personal","name":"personal","component":"personal/index","meta":{"title":"个人中心","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin","common"],"icon":"iconfont icon-gerenzhongxin"}}]}
    @RequestMapping("/test")
    public String test() {
        int i = 0;
        int j = 1;
        int k  = j/i;
//        Student student = studentService.findStudentById("1");
//        System.out.println(student);
        logger.info("获取权限集合");
        String s  =  "{\"code\":0,\"type\":\"adminMenu\",\"data\":[{\"path\":\"/home\",\"name\":\"home\",\"component\":\"home/index\",\"meta\":{\"title\":\"首页\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":true,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-shouye\"}},{\"path\":\"/system\",\"name\":\"system\",\"component\":\"layout/routerView/parent\",\"redirect\":\"/system/menu\",\"meta\":{\"title\":\"系统设置\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-xitongshezhi\"},\"children\":[{\"path\":\"/system/menu\",\"name\":\"systemMenu\",\"component\":\"system/menu/index\",\"meta\":{\"title\":\"菜单管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-caidan\"}},{\"path\":\"/system/role\",\"name\":\"systemRole\",\"component\":\"system/role/index\",\"meta\":{\"title\":\"角色管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-ColdDrink\"}},{\"path\":\"/system/dept\",\"name\":\"systemDept\",\"component\":\"system/dept/index\",\"meta\":{\"title\":\"部门管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-OfficeBuilding\"}},{\"path\":\"/system/user\",\"name\":\"systemUser\",\"component\":\"system/user/index\",\"meta\":{\"title\":\"用户管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-icon-\"}},{\"path\":\"/system/dic\",\"name\":\"systemDic\",\"component\":\"system/dic/index\",\"meta\":{\"title\":\"字典管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-SetUp\"}}]},{\"path\":\"/personal\",\"name\":\"personal\",\"component\":\"personal/index\",\"meta\":{\"title\":\"个人中心\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-gerenzhongxin\"}}]}";
        logger.info(s);
        return s;
    }
    @PostMapping("/test1")
    public ResultObject test1() {
        logger.info("test1");
        return ResultObject.fail();
    }
    @RequestMapping("/test2")
    public String test2() {
        KeyPair pair = SecureUtil.generateKeyPair("SM2");
        logger.info("publicKey:"+bytesToBase64(pair.getPrivate().getEncoded()));
        logger.info("privateKey:"+bytesToBase64(pair.getPublic().getEncoded()));
        return "122";
    }
    /**
     * 字节数组转Base64编码
     *
     * @param bytes 字节数组
     * @return Base64编码
     */
    private static String bytesToBase64(byte[] bytes) {
        byte[] encodedBytes = Base64.getEncoder().encode(bytes);
        return new String(encodedBytes, StandardCharsets.UTF_8);
    }

    //{"code":0,"type":"adminMenu","data":[{"path":"/home","name":"home","component":"home/index","meta":{"title":"首页","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":true,"isIframe":false,"roles":["admin","common"],"icon":"iconfont icon-shouye"}},{"path":"/system","name":"system","component":"layout/routerView/parent","redirect":"/system/menu","meta":{"title":"系统设置","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"iconfont icon-xitongshezhi"},"children":[{"path":"/system/menu","name":"systemMenu","component":"system/menu/index","meta":{"title":"菜单管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"iconfont icon-caidan"}},{"path":"/system/dept","name":"systemDept","component":"system/dept/index","meta":{"title":"部门管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"ele-OfficeBuilding"}},{"path":"/system/role","name":"systemRole","component":"system/role/index","meta":{"title":"角色管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"ele-ColdDrink"}},{"path":"/system/user","name":"systemUser","component":"system/user/index","meta":{"title":"用户管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"iconfont icon-icon-"}},{"path":"/system/dic","name":"systemDic","component":"system/dic/index","meta":{"title":"字典管理","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin"],"icon":"ele-SetUp"}}]},{"path":"/personal","name":"personal","component":"personal/index","meta":{"title":"个人中心","isLink":"","isHide":false,"isKeepAlive":true,"isAffix":false,"isIframe":false,"roles":["admin","common"],"icon":"iconfont icon-gerenzhongxin"}}]}

    @RequestMapping("/getMenu")
    public String getMenu(@RequestParam("roleName") String roleName) {
        System.out.println(roleName+"获取动态路由");
        if("超级管理员".equals(roleName)){
            return "{\"code\":0,\"type\":\"adminMenu\",\"data\":[{\"path\":\"/home\",\"name\":\"home\",\"component\":\"home/index\",\"meta\":{\"title\":\"首页\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":true,\"isIframe\":false,\"icon\":\"iconfont icon-shouye\"}},{\"path\":\"/system\",\"name\":\"system\",\"component\":\"layout/routerView/parent\",\"redirect\":\"/system/menu\",\"meta\":{\"title\":\"系统设置\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-xitongshezhi\"},\"children\":[{\"path\":\"/system/menu\",\"name\":\"systemMenu\",\"component\":\"system/menu/index\",\"meta\":{\"title\":\"菜单管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-caidan\"}},{\"path\":\"/system/dept\",\"name\":\"systemDept\",\"component\":\"system/dept/index\",\"meta\":{\"title\":\"部门管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-OfficeBuilding\"}},{\"path\":\"/system/role\",\"name\":\"systemRole\",\"component\":\"system/role/index\",\"meta\":{\"title\":\"角色管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-ColdDrink\"}},{\"path\":\"/system/user\",\"name\":\"systemUser\",\"component\":\"system/user/index\",\"meta\":{\"title\":\"用户管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-icon-\"}},{\"path\":\"/system/dic\",\"name\":\"systemDic\",\"component\":\"system/dic/index\",\"meta\":{\"title\":\"字典管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-SetUp\"}}]},{\"path\":\"/personal\",\"name\":\"personal\",\"component\":\"personal/index\",\"meta\":{\"title\":\"个人中心\",\"isLink\":\"\",\"isHide\":true,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"icon\":\"iconfont icon-gerenzhongxin\"}}]}";
//            return "{\"code\":0,\"type\":\"adminMenu\",\"data\":[{\"path\":\"/home\",\"name\":\"home\",\"component\":\"home/index\",\"meta\":{\"title\":\"首页\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":true,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-shouye\"}},{\"path\":\"/system\",\"name\":\"system\",\"component\":\"layout/routerView/parent\",\"redirect\":\"/system/menu\",\"meta\":{\"title\":\"系统设置\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-xitongshezhi\"},\"children\":[{\"path\":\"/system/menu\",\"name\":\"systemMenu\",\"component\":\"system/menu/index\",\"meta\":{\"title\":\"菜单管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-caidan\"}},{\"path\":\"/system/dept\",\"name\":\"systemDept\",\"component\":\"system/dept/index\",\"meta\":{\"title\":\"部门管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-OfficeBuilding\"}},{\"path\":\"/system/role\",\"name\":\"systemRole\",\"component\":\"system/role/index\",\"meta\":{\"title\":\"角色管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-ColdDrink\"}},{\"path\":\"/system/user\",\"name\":\"systemUser\",\"component\":\"system/user/index\",\"meta\":{\"title\":\"用户管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-icon-\"}},{\"path\":\"/system/dic\",\"name\":\"systemDic\",\"component\":\"system/dic/index\",\"meta\":{\"title\":\"字典管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-SetUp\"}}]},{\"path\":\"/personal\",\"name\":\"personal\",\"component\":\"personal/index\",\"meta\":{\"title\":\"个人中心\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-gerenzhongxin\"}}]}";
//            return "{\"code\":0,\"type\":\"adminMenu\",\"data\":[{\"path\":\"/home\",\"name\":\"home\",\"component\":\"home/index\",\"meta\":{\"title\":\"首页\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":true,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-shouye\"}},{\"path\":\"/system\",\"name\":\"system\",\"component\":\"layout/routerView/parent\",\"redirect\":\"/system/menu\",\"meta\":{\"title\":\"系统设置\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-xitongshezhi\"},\"children\":[{\"path\":\"/system/menu\",\"name\":\"systemMenu\",\"component\":\"system/menu/index\",\"meta\":{\"title\":\"菜单管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-caidan\"}},{\"path\":\"/system/dept\",\"name\":\"systemDept\",\"component\":\"system/dept/index\",\"meta\":{\"title\":\"部门管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-OfficeBuilding\"}},{\"path\":\"/system/role\",\"name\":\"systemRole\",\"component\":\"system/role/index\",\"meta\":{\"title\":\"角色管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-ColdDrink\"}},{\"path\":\"/system/user\",\"name\":\"systemUser\",\"component\":\"system/user/index\",\"meta\":{\"title\":\"用户管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-icon-\"}},{\"path\":\"/system/dic\",\"name\":\"systemDic\",\"component\":\"system/dic/index\",\"meta\":{\"title\":\"字典管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-SetUp\"}}]},{\"path\":\"/personal\",\"name\":\"personal\",\"component\":\"personal/index\",\"meta\":{\"title\":\"个人中心\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-gerenzhongxin\"}},{\"path\":\"/student\",\"name\":\"student\",\"component\":\"student/index\",\"meta\":{\"title\":\"学生管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-shuju\"}},{\"path\":\"/teacher\",\"name\":\"teacher\",\"component\":\"teacher/index\",\"meta\":{\"title\":\"教师管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-gerenzhongxin\"}}]}";
        } else {
            return "{\"code\":0,\"type\":\"adminMenu\",\"data\":[{\"path\":\"/home\",\"name\":\"home\",\"component\":\"home/index\",\"meta\":{\"title\":\"首页\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":true,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-shouye\"}},{\"path\":\"/system\",\"name\":\"system\",\"component\":\"layout/routerView/parent\",\"redirect\":\"/system/menu\",\"meta\":{\"title\":\"系统设置\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-xitongshezhi\"},\"children\":[{\"path\":\"/system/menu\",\"name\":\"systemMenu\",\"component\":\"system/menu/index\",\"meta\":{\"title\":\"菜单管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-caidan\"}},{\"path\":\"/system/role\",\"name\":\"systemRole\",\"component\":\"system/role/index\",\"meta\":{\"title\":\"角色管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-ColdDrink\"}},{\"path\":\"/system/dept\",\"name\":\"systemDept\",\"component\":\"system/dept/index\",\"meta\":{\"title\":\"部门管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-OfficeBuilding\"}},{\"path\":\"/system/user\",\"name\":\"systemUser\",\"component\":\"system/user/index\",\"meta\":{\"title\":\"用户管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"iconfont icon-icon-\"}},{\"path\":\"/system/dic\",\"name\":\"systemDic\",\"component\":\"system/dic/index\",\"meta\":{\"title\":\"字典管理\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\"],\"icon\":\"ele-SetUp\"}}]},{\"path\":\"/personal\",\"name\":\"personal\",\"component\":\"personal/index\",\"meta\":{\"title\":\"个人中心\",\"isLink\":\"\",\"isHide\":false,\"isKeepAlive\":true,\"isAffix\":false,\"isIframe\":false,\"roles\":[\"admin\",\"common\"],\"icon\":\"iconfont icon-gerenzhongxin\"}}]}";
        }
    }

    @RequestMapping("/fileTest")
    public String fileTest(@RequestParam MultipartFile file) {
        System.out.println("上传文件开始");
        return "123";
    }
}

